﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/SiteContent.Master" AutoEventWireup="true"
    CodeBehind="Warehouses.aspx.cs" Inherits="Warehouse.Web.Management.Warehouses" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .moduleheader .moduleheadertoolbar > * {
            margin: 16px 5px 0 5px;
        }
        .datatable {
            width: 100%;
        }
        .col_name {
            width: 100px;
        }
        .col_type {
            width: 80px;
        }
        .col_des {
        }
        .col_op {
            width: 60px;
        }
    </style>

    <script type="text/javascript">
        var HOUSETYPES = [{ value: 2, label: "实体仓库" }, { value: 1, label: "虚拟仓库"}];
        function addHouse() {
            var html = ['<div class="dialog">'];
            html.push('<table class="infotable">');
            html.push('<tr><td><label>仓库名</label></td><td><input type="text" field="Name"/></td></tr>');
            html.push('<tr><td><label>类型</label></td><td><select field="HouseType">');
            $.each(HOUSETYPES, function(index) {
                html.push('<option value="' + this.value + '"');
                if (index == 0) {
                    html.push(' selected="selected" ');
                }
                html.push('>' + this.label + '</option>');
            });
            html.push('</select></td></tr>');
            html.push('<tr><td><label>描述</label></td><td><textarea field="Description"></textarea></td></tr>');
            html.push('</table>');
            html.push('</div>');
            var dialog = top.showDialog(html.join(''), { title: "新建仓库",
                width: 400,
                height: 220,
                resizable: false,
                modal: true,
                buttons: {
                    "确定": function() {
                        var data = Util.getFields(dialog);
                        if (!data.Name) {
                            alert("请输入仓库名");
                            return;
                        }
                        data.HouseType = data.HouseType - 0;
                        Util.post("", $.extend(true, { action: "AddHouse" }, data), function(succeed, data, err) {
                            if (succeed) {
                                alert('保存成功');
                                dialog.dialog('close');
                                window.location.reload();
                            } else {
                                alert(err);
                            }
                        }, { autoOverlay: true });
                    },
                    "取消": function() {
                        dialog.dialog('close');
                    }
                }
            });
        }
        function modifyHouse(houseId) {
            Util.get("./Warehouses.aspx", { action: "GetHouse", HouseID: houseId }, function(succeed, data, err) {
                if (succeed) {
                    var html = ['<div class="dialog">'];
                    html.push('<table class="infotable">');
                    html.push('<tr><td><label>仓库名</label></td><td><input type="hidden" field="ID" value="' + data.ID + '"/><input type="text" field="Name" value="' + data.Name + '"/></td></tr>');
                    html.push('<tr><td><label>类型</label></td><td><select field="HouseType">');
                    $.each(HOUSETYPES, function(index) {
                        html.push('<option value="' + this.value + '"');
                        if (this.value == data.HouseType) {
                            html.push(' selected="selected" ');
                        }
                        html.push('>' + this.label + '</option>');
                    });
                    html.push('</select></td></tr>');
                    html.push('<tr><td><label>描述</label></td><td><textarea field="Description">' + data.Description + '</textarea></td></tr>');
                    html.push('</table>');
                    html.push('</div>');
                    var dialog = top.showDialog(html.join(''), { title: "新建仓库",
                        width: 400,
                        height: 220,
                        resizable: false,
                        modal: true,
                        buttons: {
                            "确定": function() {
                                var data = Util.getFields(dialog);
                                if (!data.Name) {
                                    alert("请输入仓库名");
                                    return;
                                }
                                data.HouseType = data.HouseType - 0;
                                Util.post("", $.extend(true, { action: "SaveHouse" }, data), function(succeed, data, err) {
                                    if (succeed) {
                                        alert('保存成功');
                                        dialog.dialog('close');
                                        window.location.reload();
                                    } else {
                                        alert(err);
                                    }
                                }, { autoOverlay: true });
                            },
                            "取消": function() {
                                dialog.dialog('close');
                            }
                        }
                    });
                } else {
                    alert(err);
                }
            }, { autoOverlay: true });
        }
        function deleteHouse(houseId) {
            if (confirm("您确认要删除该仓库吗？")) {
                Util.post("", { action: "DeleteHouse", HouseID: houseId }, function(succeed, data, err) {
                    if (succeed) {
                        alert('删除成功');
                        window.location.reload();
                    } else {
                        alert(err);
                    }
                }, { autoOverlay: true });
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="moduleheader">
        <h4>
            仓库管理</h4>
        <div class="moduleheadertoolbar">
            <input type="button" class="ui-button-refresh" onclick="window.location.reload();"
                value="刷新" />
            <uc:AuthorityControl runat="server" Action="AddHouse">
                <input type="button" class="ui-button-add" onclick="addHouse();" value="新建仓库" />
            </uc:AuthorityControl>
        </div>
    </div>
    <div class="modulecontent">
        <table class="datatable">
            <tr>
                <th class="col_name">
                    名称
                </th>
                <th class="col_type">
                    类型
                </th>
                <th class="col_des">
                    描述
                </th>
                <th class="col_op">
                    管理
                </th>
            </tr>
            <asp:Repeater ID="rptHouses" runat="server">
                <ItemTemplate>
                    <tr>
                        <td class="col_name">
                            <%# Eval("Name") %>
                        </td>
                        <td class="col_type">
                            <%# GetWarehouseType((Warehouse.DataAccess.WarehouseType)Eval("HouseType"))%>
                        </td>
                        <td class="col_des">
                            <%# Eval("Description") %>
                        </td>
                        <td class="col_op">
                            <uc:AuthorityControl runat="server" Action="SaveHouse">
                                <input type="button" class="icon-button-edit" title="编辑" value=" " onclick="modifyHouse(<%# Eval("ID") %>);" />
                            </uc:AuthorityControl>
                            <uc:AuthorityControl runat="server" Action="DeleteHouse">
                                <input type="button" class="icon-button-delete" title="删除" value=" " onclick="deleteHouse(<%# Eval("ID") %>);" />
                            </uc:AuthorityControl>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </div>
</asp:Content>
